package org.looom.orglooomschool;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity2 extends AppCompatActivity{

    protected EditText editTextStudentId;
    protected TextView textViewResult;
    protected Button queryButton;

    // 模拟的学号和成绩数据
    String[] studentIds = {"1001", "1002", "1003", "1004"};
    String[] grades = {"90", "85", "92", "78"};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.button3);

        editTextStudentId = findViewById(R.id.ed1);
        textViewResult = findViewById(R.id.textViewResult);
        queryButton = findViewById(R.id.queryButton);

        queryButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String studentId = editTextStudentId.getText().toString();
                String grade = findGrade(studentId);
                if (grade != null) {
                    textViewResult.setText("您的成绩为：" + grade);
                } else {
                    textViewResult.setText("您的成绩为：查询失败，学号不存在！");
                }
            }
        });
    }
    // 查询成绩的方法
    private String findGrade(String studentId) {
        for (int i = 0; i < studentIds.length; i++) {
            if (studentId.equals(studentIds[i])) {
                return grades[i];
            }
        }
        return null;
    }
}